package LeetCodeHot100TopInterview;

public class Q108_ArrayToBST {

    //有序数组转"平衡"二叉搜索树
    public TreeNode sortedArrayToBST(int[] nums) {
        if (nums == null || nums.length == 0){
            return null;
        }
        return process(nums, 0, nums.length - 1);
    }

    public TreeNode process(int[] nums, int left, int right){
        if (left > right){
            return null;
        }
        //找中点
        int mid =  (left + right) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = process(nums, left, mid - 1);
        root.right = process(nums, mid + 1, right);
        return root;
    }

}
